package com.mitei.fwk.search;

public class StringSearcher {

	public static Boolean isInString(String token) {			
		return token.contains(token);
	}
	
	public static String replaceTokenInString(String string, Object oldToken, Object newToken) {

		String [] leftAndRightString = null;
		leftAndRightString = string.split(oldToken.toString());
		
		if(leftAndRightString.length == 2){
			return leftAndRightString[0] + newToken.toString() + leftAndRightString[1];
		} else {
			return null;
		}
		
		
	}
	
	public static String replaceTokenInString2(String string, Object oldToken, Object newToken) {
		int tokenIndex = string.indexOf(oldToken.toString());
		if(tokenIndex == -1) return null;
		
		int tokenEndIndex = tokenIndex + oldToken.toString().length() - 1;
		String leftString = string.substring(0, tokenIndex - 1);
		String rightString = string.substring(tokenEndIndex + 1);
		
		if(string.charAt(tokenIndex - 1) == 92) return leftString + "\\" + newToken.toString() + rightString;
		
		return leftString + newToken.toString() + rightString;
	}
	
	public static int indexOf (String[] src, String token) {
		for(int i = 0 ; i < src.length ; i++) {
			if (src[i].equals(token)) return i;
		}
		return -1;
	}
}